package jsyf.oa.web.weekplan;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.weekplan.WeekPlanFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by LT on 2018/3/19.
 */
@Api(value = "周计划接口", description = "周计划接口")
@Controller
@RequestMapping("/weekPlan")
public class WeekPlanController {
    @Resource
    private WeekPlanFacade weekPlanFacade;
    @ResponseBody
    @RequestMapping(value = "/add.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "添加周计划",
            notes = "添加周计划 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "[{\n" +
            "\t\n" +
            "\tcreateTime: '2018-03-19 17:13:44',\n" +
            "\tcreateUserId: '4545',\n" +
            "\tcustomerAddress: '山西',\n" +
            "\tcustomerName:'555',\n" +
            "\tid: '201803191713408793BCB1A14C1A51E1',\n" +
            "\tintentionDevice: '挖掘机',\n" +
            "\tlastVisitTime: '2018-03-20',\n" +
            "\tremake: '',\n" +
            "\tweekTime: '2018-03-22 00:00:00',\n" +
            "\tweekName: '星期三'\n" +
            "}, {\n" +
            "\t\n" +
            "\tcreateTime: '2018-03-19 17:13:44',\n" +
            "\tcreateUserId: '4545',\n" +
            "\tcustomerAddress: '山西',\n" +
            "\tcustomerName:'555',\n" +
            "\tid: '201803191713408793BCB1A14C1A51E1',\n" +
            "\tintentionDevice: '挖掘机',\n" +
            "\tlastVisitTime: '2018-03-20',\n" +
            "\tremake: '',\n" +
            "\tweekTime: '2018-03-22 00:00:00',\n" +
            "\tweekName: '星期三'\n" +
            "}]", dataType = "String", paramType = "body")
    public void add(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        String records = this.weekPlanFacade.add(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
    }

    @ResponseBody
    @RequestMapping(value = "/removeById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "删除周计划",
            notes = "删除周计划 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{id:''}", dataType = "String", paramType = "body")
    public void removeById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.weekPlanFacade.removeById(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
    }

    @ResponseBody
    @RequestMapping(value = "/update.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "修改周计划",
            notes = "修改周计划 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "[{id:''},{id:''}]", dataType = "String", paramType = "body")
    public void update(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.weekPlanFacade.update(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));


    }

    @ResponseBody
    @RequestMapping(value = "/getWeek.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询周计划",
            notes = "查询周计划 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "\"{createUserId:'4545',weekTime:'2018-03-21 00:00:00'}\"", dataType = "String", paramType = "body")
    public void getWeek(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {

        JSONObject records = this.weekPlanFacade.getWeek(jsonData);
        if (records!= null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
    @ResponseBody
    @RequestMapping(value = "/getWeekList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询周计划列表",
            notes = "查询周计划列表",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{companyId:'2017121617494062A6AF2EF6ED9B27C6'", dataType = "String", paramType = "body")
    public void getWeekList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        JSONObject records = this.weekPlanFacade.getWeekList(jsonObject);
        if (records!= null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
    @ResponseBody
    @RequestMapping(value = "/getNameAndTel.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "模糊查询姓名电话",
            notes = "模糊查询姓名电话 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{key:'',createUserId:''}", dataType = "String", paramType = "body")
    public void getNameAndTel(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {

        List<JSONObject> records = this.weekPlanFacade.getNameAndTel(jsonData);
        if (records!= null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
    @ResponseBody
    @RequestMapping(value = "/getCompanyList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取大客户列表",
            notes = "获取大客户列表 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void getCompanyList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonObject = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        List<JSONObject> records = this.weekPlanFacade.getCompanyList(jsonObject);
        if (records!= null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
}
